home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9206.ARJ / 1006092A < prev    next >
Text File  |  1992-06-02  |  894b  |  51 lines

  1. /* LISTING 7 */
  2.  
  3. #define DM3init
  4.  
  5. #define DM3type                 double **
  6.  
  7. DM3init;
  8.  
  9. DM3type DM3alloc(int r, int c) {
  10.     int i;
  11.     DM3type p;
  12.  
  13.     p = (DM3type)
  14.         malloc((unsigned)(1+r)*sizeof(double *));  
  15.     for( i=0; i<r; ++i )
  16.         p[i] = (double *)
  17.             malloc((unsigned)c*sizeof(double));
  18.     p[i] = (double *)0;
  19.     return p;
  20. }
  21.  
  22. #define DM3item(x,i,j)          x[i][j]
  23.  
  24. void DM3free(DM3type x) {
  25.     int i;
  26.  
  27.     for( i=0; x[i] != (double *)0; ++i ) {
  28.         free((void *)x[i]);
  29.     }
  30.     free((void *)x);
  31. }
  32.  
  33. main()
  34. {
  35.     DM3type m;
  36.     int i,j;
  37.  
  38.     m = DM3alloc(7,13);
  39.     for(i=0; i<7; ++i)
  40.         for(j=0; j<13; ++j)
  41.             DM3item(m,i,j) = (double) (i*100)+j;
  42.  
  43.     for(i=0; i<7; ++i) {
  44.         for(j=0; j<13; ++j)
  45.             printf("%3g ",DM3item(m,i,j) );
  46.         printf("\n");
  47.     }
  48.     DM3free(m);
  49. }
  50.  
  51.